import { AllApiinterface } from '../config/interface'

const API: AllApiinterface = {}
const regExp = new RegExp(/.\/(\w+).[a-z]+$/i)
const requireApi = require.context('./', true, /.(js)|(ts)$/)

requireApi.keys().forEach((element) => {
  const config = requireApi(element)
  if (regExp.test(element)) {
    RegExp.$1 !== 'index' && (API[RegExp.$1] = config.default)
  } else {
    console.error(`${element}'api文件名配置错误，只支持英文和数字`)
  }
})

export default API
